/**
 * <copyright>
 * </copyright>
 *

 */
package it.unibo.iss.domotica.domoticDsl.impl;

import it.unibo.iss.domotica.domoticDsl.DomoticDslPackage;
import it.unibo.iss.domotica.domoticDsl.Elettrodomestico;
import it.unibo.iss.domotica.domoticDsl.Properties;
import it.unibo.iss.domotica.domoticDsl.Sensor;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>System</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link it.unibo.iss.domotica.domoticDsl.impl.SystemImpl#getName <em>Name</em>}</li>
 *   <li>{@link it.unibo.iss.domotica.domoticDsl.impl.SystemImpl#getPackage <em>Package</em>}</li>
 *   <li>{@link it.unibo.iss.domotica.domoticDsl.impl.SystemImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link it.unibo.iss.domotica.domoticDsl.impl.SystemImpl#getElettrodomestico <em>Elettrodomestico</em>}</li>
 *   <li>{@link it.unibo.iss.domotica.domoticDsl.impl.SystemImpl#getSensors <em>Sensors</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SystemImpl extends MinimalEObjectImpl.Container implements it.unibo.iss.domotica.domoticDsl.System
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getPackage() <em>Package</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPackage()
   * @generated
   * @ordered
   */
  protected it.unibo.iss.domotica.domoticDsl.Package package_;

  /**
   * The cached value of the '{@link #getProperties() <em>Properties</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getProperties()
   * @generated
   * @ordered
   */
  protected Properties properties;

  /**
   * The cached value of the '{@link #getElettrodomestico() <em>Elettrodomestico</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getElettrodomestico()
   * @generated
   * @ordered
   */
  protected EList<Elettrodomestico> elettrodomestico;

  /**
   * The cached value of the '{@link #getSensors() <em>Sensors</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSensors()
   * @generated
   * @ordered
   */
  protected EList<Sensor> sensors;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected SystemImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return DomoticDslPackage.Literals.SYSTEM;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, DomoticDslPackage.SYSTEM__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public it.unibo.iss.domotica.domoticDsl.Package getPackage()
  {
    return package_;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetPackage(it.unibo.iss.domotica.domoticDsl.Package newPackage, NotificationChain msgs)
  {
    it.unibo.iss.domotica.domoticDsl.Package oldPackage = package_;
    package_ = newPackage;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DomoticDslPackage.SYSTEM__PACKAGE, oldPackage, newPackage);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setPackage(it.unibo.iss.domotica.domoticDsl.Package newPackage)
  {
    if (newPackage != package_)
    {
      NotificationChain msgs = null;
      if (package_ != null)
        msgs = ((InternalEObject)package_).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DomoticDslPackage.SYSTEM__PACKAGE, null, msgs);
      if (newPackage != null)
        msgs = ((InternalEObject)newPackage).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DomoticDslPackage.SYSTEM__PACKAGE, null, msgs);
      msgs = basicSetPackage(newPackage, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, DomoticDslPackage.SYSTEM__PACKAGE, newPackage, newPackage));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Properties getProperties()
  {
    return properties;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetProperties(Properties newProperties, NotificationChain msgs)
  {
    Properties oldProperties = properties;
    properties = newProperties;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DomoticDslPackage.SYSTEM__PROPERTIES, oldProperties, newProperties);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setProperties(Properties newProperties)
  {
    if (newProperties != properties)
    {
      NotificationChain msgs = null;
      if (properties != null)
        msgs = ((InternalEObject)properties).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DomoticDslPackage.SYSTEM__PROPERTIES, null, msgs);
      if (newProperties != null)
        msgs = ((InternalEObject)newProperties).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DomoticDslPackage.SYSTEM__PROPERTIES, null, msgs);
      msgs = basicSetProperties(newProperties, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, DomoticDslPackage.SYSTEM__PROPERTIES, newProperties, newProperties));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Elettrodomestico> getElettrodomestico()
  {
    if (elettrodomestico == null)
    {
      elettrodomestico = new EObjectContainmentEList<Elettrodomestico>(Elettrodomestico.class, this, DomoticDslPackage.SYSTEM__ELETTRODOMESTICO);
    }
    return elettrodomestico;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Sensor> getSensors()
  {
    if (sensors == null)
    {
      sensors = new EObjectContainmentEList<Sensor>(Sensor.class, this, DomoticDslPackage.SYSTEM__SENSORS);
    }
    return sensors;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case DomoticDslPackage.SYSTEM__PACKAGE:
        return basicSetPackage(null, msgs);
      case DomoticDslPackage.SYSTEM__PROPERTIES:
        return basicSetProperties(null, msgs);
      case DomoticDslPackage.SYSTEM__ELETTRODOMESTICO:
        return ((InternalEList<?>)getElettrodomestico()).basicRemove(otherEnd, msgs);
      case DomoticDslPackage.SYSTEM__SENSORS:
        return ((InternalEList<?>)getSensors()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case DomoticDslPackage.SYSTEM__NAME:
        return getName();
      case DomoticDslPackage.SYSTEM__PACKAGE:
        return getPackage();
      case DomoticDslPackage.SYSTEM__PROPERTIES:
        return getProperties();
      case DomoticDslPackage.SYSTEM__ELETTRODOMESTICO:
        return getElettrodomestico();
      case DomoticDslPackage.SYSTEM__SENSORS:
        return getSensors();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case DomoticDslPackage.SYSTEM__NAME:
        setName((String)newValue);
        return;
      case DomoticDslPackage.SYSTEM__PACKAGE:
        setPackage((it.unibo.iss.domotica.domoticDsl.Package)newValue);
        return;
      case DomoticDslPackage.SYSTEM__PROPERTIES:
        setProperties((Properties)newValue);
        return;
      case DomoticDslPackage.SYSTEM__ELETTRODOMESTICO:
        getElettrodomestico().clear();
        getElettrodomestico().addAll((Collection<? extends Elettrodomestico>)newValue);
        return;
      case DomoticDslPackage.SYSTEM__SENSORS:
        getSensors().clear();
        getSensors().addAll((Collection<? extends Sensor>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case DomoticDslPackage.SYSTEM__NAME:
        setName(NAME_EDEFAULT);
        return;
      case DomoticDslPackage.SYSTEM__PACKAGE:
        setPackage((it.unibo.iss.domotica.domoticDsl.Package)null);
        return;
      case DomoticDslPackage.SYSTEM__PROPERTIES:
        setProperties((Properties)null);
        return;
      case DomoticDslPackage.SYSTEM__ELETTRODOMESTICO:
        getElettrodomestico().clear();
        return;
      case DomoticDslPackage.SYSTEM__SENSORS:
        getSensors().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case DomoticDslPackage.SYSTEM__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case DomoticDslPackage.SYSTEM__PACKAGE:
        return package_ != null;
      case DomoticDslPackage.SYSTEM__PROPERTIES:
        return properties != null;
      case DomoticDslPackage.SYSTEM__ELETTRODOMESTICO:
        return elettrodomestico != null && !elettrodomestico.isEmpty();
      case DomoticDslPackage.SYSTEM__SENSORS:
        return sensors != null && !sensors.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //SystemImpl
